package com.itheima.dao;

import com.itheima.domain.Student;

import java.util.ArrayList;

/*
数据操作类
集合
增
删
改
查
根据学号查
 */
public class StudentDao {
    private static ArrayList<Student> list= new ArrayList<>();
    public void addstudent(Student student){
        list.add(student);
    }
    public void deleteStudentBySid(String sid){
        int index = getIndex(sid);
        list.remove(index);
    }
    public void updateStudent(String  sid,Student newStu){
        int index = getIndex(sid);
        list.set(index,newStu);
    }
    public ArrayList<Student> findAllstudents(){
        return list;
    }
    //根据学号查索引
    //参数
    //返回值类型
    public int getIndex(String sid){
        for (int i = 0; i < list.size(); i++) {
            Student student = list.get(i);
            if(student.getSid().equals(sid)){
                return i;
            }
        }
        return -1;
    }




}
